package com.huayi.datagovernance.controller;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huayi.datagovernance.common.SysConstant;
import com.huayi.datagovernance.dao.master.IscUserLocextMapper;
import com.huayi.datagovernance.dto.AppLogDto;
import com.huayi.datagovernance.dto.MapRequest;
import com.huayi.datagovernance.dto.YzyServiceRequest;
import com.huayi.datagovernance.entity.TYwTask;
import com.huayi.datagovernance.entity.TYwTaskYk;
import com.huayi.datagovernance.entity.TZyRcvInfo;
import com.huayi.datagovernance.exception.BizException;
import com.huayi.datagovernance.service.DeviceService;
import com.huayi.datagovernance.service.FileService;
import com.huayi.datagovernance.service.TZyRcvInfoService;
import com.huayi.datagovernance.utils.GzipUtil;
import com.huayi.datagovernance.utils.JwtUtils;
import com.huayi.datagovernance.vo.ResponseResult;
import com.huayi.datagovernance.vo.WorkOrderPageVo;
import common.parent.system.tokenauth.DecodeTokenInfoDTO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 模型服务 控制器
 *
 * @version 1.0
 * @date 2021/4/21 20:03
 */
@RestController
@RequestMapping({"/datagovernance/device"})
@Api(tags = "模型服务", description = "模型相关服务（出图，批量建模，修改，删除..）")
@Slf4j
public class DeviceController {

    @Resource
    private DeviceService deviceService;

    @Resource
    FileService fileService;

    @Resource
    IscUserLocextMapper userDao;

    @Resource
    TZyRcvInfoService tZyRcvInfoService;

    /**
     * @api {post} /datagovernance/device/outPic 1、出图
     * @apiGroup device
     * @apiName outPic
     * @apiDescription 出图（待办、已办）,出图数据为Base64编码后的字符串
     * @apiVersion 1.0.0
     * @apiParam {String} versionid  版本号（getMessageList接口返回）
     * @apiParam {String} tqsbid  台区设备id（getMessageList接口返回）
     * @apiParam {String} gdtype  工单类型：1-专线，2-台区，3-业扩，4-高压核查
     * @apiParam {String} taskStatus  任务状态：1-已办，0-待办
     * @apiParamExample {json} 请求示例：
     * {"data":{"versionid":"100787422","tqsbid":"B12E0401-CF28-45DB-92A6-473E42C24A0D-83734","gdtype":"2","taskStatus":1},"serviceCode":"app_outPic"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} data 返回结果
     * @apiSuccessExample {json} 成功返回示例：
     * {"success": true, "msg": "响应成功","data": "H4sIAAAAAAAAAKtWSktNLCktSi1WsoqO1VEqqSxIVbJScoMIOufn5KQml2Tm 5ynVAgByXN7VKgAAAA=="}
     */
    @PostMapping({"/outPic"})
    public ResponseResult<String> outPic(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        ResponseResult<JSONObject> result = deviceService.outPic(serviceRequest.getData());
        try {
            return ResponseResult.success(GzipUtil.compress(result.getData().toString(), CharsetUtil.UTF_8));
        } catch (Exception e) {
            log.error("出图数据压缩失败", e);
            return ResponseResult.failed("出图失败");
        }
    }
    //本地测试
   /* public ResponseResult<String> outPic(@RequestBody JSONObject jsonObject) {
        ResponseResult<JSONObject> result = deviceService.outPic(jsonObject);
        try {
            return ResponseResult.success(GzipUtil.compress(result.getData().toString(), CharsetUtil.UTF_8));
        } catch (Exception e) {
            log.error("出图数据压缩失败", e);
            return ResponseResult.failed("出图失败");
        }
    }
*/
    /**
     * @api {post} /datagovernance/device/getMessageList 2、获取下发的工单任务（分页）
     * @apiGroup device
     * @apiName getMessageList
     * @apiDescription 查询处理的工单列表，自定义条件，分页
     * @apiVersion 1.0.0
     * @apiParam {String} searchname  工单名称关键字
     * @apiParam {int} currPage  页码
     * @apiParam {int} currPage  条数
     * @apiParam {int} isdone  0-代办/1-已办
     * @apiParam {String} userid  用户ID
     * @apiParam {String} orgNo  单位编号
     * @apiParam {String} gdtype  工单类型：1-专线，2-台区，3-业扩，4-高压核查
     * @apiParamExample {json} 请求示例：
     * {"data":{"orgNo":"1440112","serviceCode":"app_getStatisticsForTask","gdtype":"4","isdone":0,"userid":"7A5BD7FE69BA4FE8A4D0CD1202DA05FA"},"governanceToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI3QTVCRDdGRTY5QkE0RkU4QTREMENEMTIwMkRBMDVGQSIsIm9yZ05vIjoiMTQ0MDExMiIsImlzcyI6IkhVQVlZSS1TWC1EQVRBLU1BTkFHRVIiLCJleHAiOjE2MTk0MDcxMzAsInVzZXJOYW1lIjoi546L5b-X5YuHIiwidXNlck9yZ0luZm9MZXZlbEluZm8iOnsic2J6ciI6Indhbmd6eTYwMDAxIiwic3Nkc21jIjoi5Zu9572R5aSq5Y6f5L6b55S15YWs5Y-4Iiwib3Jnbm8iOiIxNDQwMTEyIiwic2J6cm1jIjoi546L5b-X5YuHIiwid2hiem1jIjoiIiwic3NkcyI6IjA1NzI1MkRGNDkwRDQ1RTZFMDUwMDA3RjAxMDA3NDM3IiwieXhkdyI6ImZmODA4MDgxNTA4NDY1MDIwMTUwYTZkZjI1N2UxYmQxIiwieXhkd21jIjoi5Zu9572R5aSq5Y6f5biC5a6i5oi35pyN5Yqh5Lit5b-DIiwid2hieiI6IiJ9LCJpYXQiOjE2MTg4MDIzMzAsInVzZXJJZCI6IjdBNUJEN0ZFNjlCQTRGRThBNEQwQ0QxMjAyREEwNUZBIn0.Vv3WynnG_bCT0SclXe2LYOYCx0AxVxIL_tqQIAX8v7c","serviceCode":"app_getMessageList"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} data 返回结果
     * @apiSuccessExample {json} 成功返回示例：
     * {"success":true,"msg":"响应成功","data":{"records":[{"oid":2544856,"name":"测试高压","tasktime":"2021-04-20 15:18:17","sfts":1,"versionid":1234567,"gdtype":4,"taskid":"2412","ssxl":null,"gdoid":586657,"tqmc":"测试高压","tqsbid":"SBID000000D2EB27BF01874689A4724FED6514A7F4","tqoid":654985,"tqmodelid":0,"isdone":0},{"oid":1652399,"name":"10kV保税区开关站待用7588间隔","tasktime":"2021-04-14 11:09:03","sfts":1,"versionid":101894740,"gdtype":4,"taskid":"434242","ssxl":null,"gdoid":1652853,"tqmc":"10kV保税区开关站待用7588间隔","tqsbid":"9719526","tqoid":681070,"tqmodelid":10000000,"isdone":0}],"total":2,"size":10,"current":1,"orders":[],"searchCount":true,"pages":1}}
     */
    @PostMapping("/getMessageList")
    public ResponseResult<IPage<WorkOrderPageVo>> getMessageList(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        JSONObject data = serviceRequest.getData();
        //解析用户信息
        DecodeTokenInfoDTO tokenInfo = JwtUtils.getAllDecodeTokenInfo(token);
        data.put(SysConstant.FIELD_USER_ID, tokenInfo.getUserId());
        //解析组织信息
        HashMap<String, String> orgMap = tokenInfo.getUserOrgInfoLevelInfoMap();
        data.put(SysConstant.FIELD_ORG_NO, orgMap.get(SysConstant.FIELD_ORG_NO));
        return deviceService.getWorkOrderPage(data);
    }

    /**
     * @api {post} /datagovernance/device/getDeviceInfo 3、获取设备详情
     * @apiGroup device
     * @apiName getDeviceInfo
     * @apiDescription 查询设备详情，优先从新建模型中查找，没有到就去下发数据中找
     * @apiVersion 1.0.0
     * @apiParam {String} sbid  设备id
     * @apiParam {String} modelid  设备子类型
     * @apiParam {String} versionid  版本号id
     * @apiParam {String} oid  资源表oid / 对应zxdata表中的sboid
     * @apiParam {String} gdtype  工单类型：1-专线，2-台区，3-业扩，4-高压核查
     * @apiParamExample {json} 请求示例：
     * {"data":{"versionid":"123654","sbid":"SBID000000F82AAA5841A449F7B3243C8095E84D64","gdtype":"4","modelid":"14000000","oid":"49279"},"governanceToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI3QTVCRDdGRTY5QkE0RkU4QTREMENEMTIwMkRBMDVGQSIsIm9yZ05vIjoiMTQ0MDExMiIsImlzcyI6IkhVQVlZSS1TWC1EQVRBLU1BTkFHRVIiLCJleHAiOjE2MTk0MDcxMzAsInVzZXJOYW1lIjoi546L5b-X5YuHIiwidXNlck9yZ0luZm9MZXZlbEluZm8iOnsic2J6ciI6Indhbmd6eTYwMDAxIiwic3Nkc21jIjoi5Zu9572R5aSq5Y6f5L6b55S15YWs5Y-4Iiwib3Jnbm8iOiIxNDQwMTEyIiwic2J6cm1jIjoi546L5b-X5YuHIiwid2hiem1jIjoiIiwic3NkcyI6IjA1NzI1MkRGNDkwRDQ1RTZFMDUwMDA3RjAxMDA3NDM3IiwieXhkdyI6ImZmODA4MDgxNTA4NDY1MDIwMTUwYTZkZjI1N2UxYmQxIiwieXhkd21jIjoi5Zu9572R5aSq5Y6f5biC5a6i5oi35pyN5Yqh5Lit5b-DIiwid2hieiI6IiJ9LCJpYXQiOjE2MTg4MDIzMzAsInVzZXJJZCI6IjdBNUJEN0ZFNjlCQTRGRThBNEQwQ0QxMjAyREEwNUZBIn0.Vv3WynnG_bCT0SclXe2LYOYCx0AxVxIL_tqQIAX8v7c","serviceCode":"app_getDeviceInfo"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} data 返回结果
     * @apiSuccessExample {json} 成功返回示例：
     * {"success":true,"msg":"响应成功","data":{"classid":140000,"shape":{"type":"geometry","value":"010200000002000000384A2E64ADE75B408EE1E490EA09434018B50A81ADE75B407B7E4659E7094340"},"dydj":22,"sbzlx":14000000,"datatype":"1","modelalias":"站外-超连接线","tqsbid":"1460338","sboid":49279,"oid":49279,"sbid":"SBID000000F82AAA5841A449F7B3243C8095E84D64"}}
     */
    @PostMapping(value = "/getDeviceInfo")
    ResponseResult<JSONObject> getDeviceInfo(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.getDeviceInfo(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/getXlList 4、获取线路列表
     * @apiGroup device
     * @apiName getXlList
     * @apiDescription 获取线路列表(新建和下发)
     * @apiVersion 1.0.0
     * @apiParam {String} sbid  设备id / tqsbid
     * @apiParam {String} versionid  版本号id
     * @apiParam {String} gdtype 工单类型：1-专线，2-台区，3-业扩，4-高压核查
     * @apiParamExample {json} 请求示例：
     * {"data":{"versionid":"1440112","sbid":"1459779","gdtype":"4"},"governanceToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI3QTVCRDdGRTY5QkE0RkU4QTREMENEMTIwMkRBMDVGQSIsIm9yZ05vIjoiMTQ0MDExMiIsImlzcyI6IkhVQVlZSS1TWC1EQVRBLU1BTkFHRVIiLCJleHAiOjE2MTk0MDcxMzAsInVzZXJOYW1lIjoi546L5b-X5YuHIiwidXNlck9yZ0luZm9MZXZlbEluZm8iOnsic2J6ciI6Indhbmd6eTYwMDAxIiwic3Nkc21jIjoi5Zu9572R5aSq5Y6f5L6b55S15YWs5Y-4Iiwib3Jnbm8iOiIxNDQwMTEyIiwic2J6cm1jIjoi546L5b-X5YuHIiwid2hiem1jIjoiIiwic3NkcyI6IjA1NzI1MkRGNDkwRDQ1RTZFMDUwMDA3RjAxMDA3NDM3IiwieXhkdyI6ImZmODA4MDgxNTA4NDY1MDIwMTUwYTZkZjI1N2UxYmQxIiwieXhkd21jIjoi5Zu9572R5aSq5Y6f5biC5a6i5oi35pyN5Yqh5Lit5b-DIiwid2hieiI6IiJ9LCJpYXQiOjE2MTg4MDIzMzAsInVzZXJJZCI6IjdBNUJEN0ZFNjlCQTRGRThBNEQwQ0QxMjAyREEwNUZBIn0.Vv3WynnG_bCT0SclXe2LYOYCx0AxVxIL_tqQIAX8v7c","serviceCode":"app_getXlList"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} data 返回结果
     * @apiSuccessExample {json} 成功返回示例：
     * {"success":true,"msg":"响应成功","data":[{"oid":null,"sbid":"1459779","sbzlx":10000001,"sbmc":"10kV4107东矿线","dydj":22},{"oid":null,"sbid":"1459779","sbzlx":10000001,"sbmc":"10kV4107东矿线","dydj":22}]}
     */
    @PostMapping(path = "/getXlList")
    ResponseResult<Object> getXlList(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.getXlList(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/autoCreateModel 5、批量建模（离线版）
     * @apiGroup device
     * @apiName autoCreateModel
     * @apiDescription 批量建模，保存前端绘制完成后的新设备，支持离线数据，会重新获取GIS库的oid和端子号进行替换
     * @apiVersion 1.0.0
     * @apiParam {String} modeldatas  建模数据（Base64编码）
     * @apiParamExample {json} 请求示例：
     * {"data"::{"modeldatas":[W3sKCSJieiI6IG51bGwsCgkiY2NycSI6IG51bGwsCgkiY2NycURhdGUiOiBudWxsLAoJImRqc2oiOiAiMjAyMS8wNC8xOSIsCgkiZHlkaiI6ICIyMiIsCgkiZHlkak5hbWUiOiAi5Lqk5rWBMTBrViIsCgkiZmJ6dCI6ICLlj5HluIMiLAoJImdlb3R5cGUiOiAiMjAwMSIsCgkiZ2ciOiBudWxsLAoJImdnTmFtZSI6IG51bGwsCgkiZ3RjeiI6IDQsCgkiZ3Rjek5hbWUiOiAi5rC05rOl5p2GIiwKCSJndHh6IjogIjIiLAoJImd0eHpOYW1lIjogbnVsbCwKCSJoZGN6IjogbnVsbCwKCSJpZCI6IDQsCgkiaXNmaXJzdCI6IG51bGwsCgkiamN4cyI6IG51bGwsCgkiamN4c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FHRVIiLCJleHAiOjE2MTk0MDcxMzAsInVzZXJOYW1lIjoi546L5b-X5YuHIiwidXNlck9yZ0luZm9MZXZlbEluZm8iOnsic2J6ciI6Indhbmd6eTYwMDAxIiwic3Nkc21jIjoi5Zu9572R5aSq5Y6f5L6b55S15YWs5Y-4Iiwib3Jnbm8iOiIxNDQwMTEyIiwic2J6cm1jIjoi546L5b-X5YuHIiwid2hiem1jIjoiIiwic3NkcyI6IjA1NzI1MkRGNDkwRDQ1RTZFMDUwMDA3RjAxMDA3NDM3IiwieXhkdyI6ImZmODA4MDgxNTA4NDY1MDIwMTUwYTZkZjI1N2UxYmQxIiwieXhkd21jIjoi5Zu9572R5aSq5Y6f5biC5a6i5oi35pyN5Yqh5Lit5b-DIiwid2hieiI6IiJ9LCJpYXQiOjE2MTg4MDIzMzAsInVzZXJJZCI6IjdBNUJEN0ZFNjlCQTRGRThBNEQwQ0QxMjAyREEwNUZBIn0.Vv3WynnG_bCT0SclXe2LYOYCx0AxVxIL_tqQIAX8v7c","serviceCode":"app_getXlList"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} data 返回结果
     * @apiSuccessExample {json} 成功返回示例：
     * {"success":true,"msg":"建模成功","data":null}
     */
    @PostMapping("autoCreateModel")
    @DSTransactional
    ResponseResult autoCreateModel(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        ResponseResult result = deviceService.autoCreateModel3(serviceRequest.getData());
        return result;
    }

    /**
     * @api {post} /datagovernance/device/commitTask 6、工单任务提交
     * @apiGroup device
     * @apiName commitTask
     * @apiDescription 批量建模完成后，提交工单任务，修改工单状态(task的sfts改为2，tqlb的isdone改成1)，回写数据到gis库，如果为朗新的工单，还需要回写变压器信息和工单状态
     * @apiVersion 1.0.0
     * @apiParam {String} versionid  版本号id
     * @apiParam {String} taskid  朗新工单号 t_yw_task的taskid / 低压表箱采集的营销工单号
     * @apiParam {String} gdtype  工单类型：1-专线，2-台区，3-业扩，4-高压核查
     * @apiParam {List} byqList  采集变压器列表：TYwTaskYk
     * @apiParam {List} bxList  采集表箱列表： TZyRcvInfo
     * @apiParamExample {json} 请求示例：
     * {"data":{"byqList":[],"versionid":"101891071","gdtype":"4","taskid":"3525242424"},"governanceToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI3QTVCRDdGRTY5QkE0RkU4QTREMENEMTIwMkRBMDVGQSIsIm9yZ05vIjoiMTQ0MDExMiIsImlzcyI6IkhVQVlZSS1TWC1EQVRBLU1BTkFHRVIiLCJleHAiOjE2MTk0MDcxMzAsInVzZXJOYW1lIjoi546L5b-X5YuHIiwidXNlck9yZ0luZm9MZXZlbEluZm8iOnsic2J6ciI6Indhbmd6eTYwMDAxIiwic3Nkc21jIjoi5Zu9572R5aSq5Y6f5L6b55S15YWs5Y-4Iiwib3Jnbm8iOiIxNDQwMTEyIiwic2J6cm1jIjoi546L5b-X5YuHIiwid2hiem1jIjoiIiwic3NkcyI6IjA1NzI1MkRGNDkwRDQ1RTZFMDUwMDA3RjAxMDA3NDM3IiwieXhkdyI6ImZmODA4MDgxNTA4NDY1MDIwMTUwYTZkZjI1N2UxYmQxIiwieXhkd21jIjoi5Zu9572R5aSq5Y6f5biC5a6i5oi35pyN5Yqh5Lit5b-DIiwid2hieiI6IiJ9LCJpYXQiOjE2MTg4MDIzMzAsInVzZXJJZCI6IjdBNUJEN0ZFNjlCQTRGRThBNEQwQ0QxMjAyREEwNUZBIn0.Vv3WynnG_bCT0SclXe2LYOYCx0AxVxIL_tqQIAX8v7c","serviceCode":"app_commitTask"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} data 返回结果
     * @apiSuccessExample {json} 成功返回示例：
     * {"success":true,"msg":"响应成功","data":{"tqmc":"孔矿线","sfts":1,"tqsbid":"8126246","oid":1648731,"gdtype":4,"tasktime":1616468634000,"tqmodelid":10000001,"versionid":101891071,"gdoid":1649184,"name":"孔矿线","tqoid":597342,"isdone":0,"taskid":"3525242424"}}
     */
    @PostMapping({"/commitTask"})
    @DSTransactional
    ResponseResult<TYwTask> commitTask(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        ResponseResult<TYwTask> result = deviceService.commitTask(serviceRequest.getData());
        if (result.isSuccess()) {
            JSONObject data = serviceRequest.getData();
            data.put("taskid", result.getData().getOid());//yw_task的oid
            deviceService.sendToGis(data);
        }
        return result;
    }
    //测试回写表箱
/*    @PostMapping({"/commitTask"})
    @DSTransactional
    ResponseResult<Boolean> commitTask(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        JSONObject jsonObject = serviceRequest.getData();
        List<TZyRcvInfo> bxList = jsonObject.getJSONArray("bxList").toJavaList(TZyRcvInfo.class);
//        List<TZyRcvInfo> bxList = JSON.parseArray(jsonObject.getString("bxList"), TZyRcvInfo.class);
        boolean isSuccess = tZyRcvInfoService.saveJlxCollectInfoBatch(bxList);
        if (isSuccess){
            return ResponseResult.success(isSuccess, "保存成功");
        }else {
            return ResponseResult.failed(isSuccess, "保存失败");
        }
    }*/



    /**
     * @api {post} /datagovernance/device/getCurrentDevicePros 6、根据问题设备查询当前设备的其他问题列表
     * @apiGroup device
     * @apiName getCurrentDevicePros
     * @apiDescription 根据问题设备查询当前设备的其他问题列表
     * @apiVersion 1.0.0
     * @apiParam {String} tqsbid  台区设备id
     * @apiParam {String} oid  设备oid
     * @apiParam {String} gdtype  工单类型：1-专线，2-台区，3-业扩，4-高压核查
     * @apiParam {List} byqList  工单类型：1-专线，2-台区，3-业扩，4-高压核查
     * @apiParamExample {json} 请求示例：
     * {"data":{"wtkey":16,"tqsbid":"2B0A7596-F348-49AD-91C6-335C322676B7-99195","yxdw":"E5D-4DC8-B3A8-799BA133855B-01304","oid":16680771,"yxdwmc":"运维检修部(检修公司)","wtname":"有图形无台账","sbname":"电缆-144511","sbzlx":320400000,"stateName":"异常","sboid":144511,"state":"0","wttype":"图数一致率检查","sbid":"SBID0000003358CCA4579F4E99A3B4C8DF1C228C94"},"governanceToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI3QTVCRDdGRTY5QkE0RkU4QTREMENEMTIwMkRBMDVGQSIsIm9yZ05vIjoiMTQ0MDExMiIsImlzcyI6IkhVQVlZSS1TWC1EQVRBLU1BTkFHRVIiLCJleHAiOjE2MTk0MDcxMzAsInVzZXJOYW1lIjoi546L5b-X5YuHIiwidXNlck9yZ0luZm9MZXZlbEluZm8iOnsic2J6ciI6Indhbmd6eTYwMDAxIiwic3Nkc21jIjoi5Zu9572R5aSq5Y6f5L6b55S15YWs5Y-4Iiwib3Jnbm8iOiIxNDQwMTEyIiwic2J6cm1jIjoi546L5b-X5YuHIiwid2hiem1jIjoiIiwic3NkcyI6IjA1NzI1MkRGNDkwRDQ1RTZFMDUwMDA3RjAxMDA3NDM3IiwieXhkdyI6ImZmODA4MDgxNTA4NDY1MDIwMTUwYTZkZjI1N2UxYmQxIiwieXhkd21jIjoi5Zu9572R5aSq5Y6f5biC5a6i5oi35pyN5Yqh5Lit5b-DIiwid2hieiI6IiJ9LCJpYXQiOjE2MTg4MDIzMzAsInVzZXJJZCI6IjdBNUJEN0ZFNjlCQTRGRThBNEQwQ0QxMjAyREEwNUZBIn0.Vv3WynnG_bCT0SclXe2LYOYCx0AxVxIL_tqQIAX8v7c","serviceCode":"app_getXlList"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} data 返回结果
     * @apiSuccessExample {json} 成功返回示例：
     * {"success":true,"msg":"响应成功","data":[{"sbzlx":320400000,"tqsbid":"2B0A7596-F348-49AD-91C6-335C322676B7-99195","sboid":144511,"yxdw":"E5D-4DC8-B3A8-799BA133855B-01304","oid":16680771,"state":"0","yxdwmc":"运维检修部(检修公司)","wtname":"有图形无台账","wttype":"图数一致率检查","sbname":"电缆-144511","sbid":"SBID0000003358CCA4579F4E99A3B4C8DF1C228C94"},{"sbzlx":320400000,"tqsbid":"2B0A7596-F348-49AD-91C6-335C322676B7-99195","sboid":144511,"yxdw":"E5D-4DC8-B3A8-799BA133855B-01304","oid":16680850,"state":"0","yxdwmc":"运维检修部(检修公司)","wtname":"图形设备必填属性填写不完整","wttype":"图形完整性检查","sbname":"电缆-144511","sbid":"SBID0000003358CCA4579F4E99A3B4C8DF1C228C94"}]}
     */
    @PostMapping("/getCurrentDevicePros")
    ResponseResult<List<JSONObject>> getCurrentDevicePros(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.getCurrentDevicePros(serviceRequest.getData());
    }
    //本地测试
    /*ResponseResult<List<JSONObject>> getCurrentDevicePros(@RequestBody JSONObject serviceRequest) {
        return deviceService.getCurrentDevicePros(serviceRequest);
    }*/

    /**
     * @api {post} /datagovernance/device/loadHtml 7、加载H5资源
     * @apiGroup device
     * @apiName loadHtml
     * @apiDescription 获取H5页面（ZIP压缩包）
     * @apiVersion 1.0.0
     * @apiParamExample {json} 传参示例-RequestParam
     * {}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值
     * {"success":true,"msg":"返回成功","result":"Base64字符串"}
     */
    @PostMapping("/loadHtml")
    ResponseResult loadHtml() {
        return fileService.loadHtml();
    }

    /**
     * @api {post} /datagovernance/device/loadMap 8、加载地图资源
     * @apiGroup device
     * @apiName loadMap
     * @apiDescription 获取地图包资源（ZIP压缩包）
     * @apiVersion 1.0.0
     * @apiParamExample {json} 传参示例-RequestParam
     * {"wtkey": "资源包ID"}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值
     * {"success":true,"msg":"返回成功","result":"Base64字符串"}
     */
    @PostMapping("/loadMap")
    ResponseResult loadMap(@RequestBody YzyServiceRequest<MapRequest>  serviceRequest){
        log.info("loadMap--入参："+ JSON.toJSONString(serviceRequest));
        return fileService.loadMap(serviceRequest.getData());
    }
//本地测试
   /* ResponseResult loadMap(@RequestBody MapRequest serviceRequest) {
        log.info("loadMap--入参：" + JSON.toJSONString(serviceRequest));
        return fileService.loadMap(serviceRequest);
    }*/

    /**
     * @api {post} /datagovernance/device/getNewSer 9、获取序列化码
     * @apiGroup device
     * @apiName getNewSer
     * @apiDescription 获取序列化码(包括端子号 ， sbid ， oid)
     * @apiVersion 1.0.0
     * @apiParam newSerno 图形OID
     * @apiParam newConno 端子号oid
     * @apiParam newSBID sbid
     * @apiParam newSerZyno 资源oid
     * @apiParam newSBLX 设备类型
     * @apiParamExample {json} 传参示例-RequestParam
     * { "newSerno": [ {"sbzlx":"14000000"}, {"sbzlx":"320100000"} ], "newConno": [ {"sbzlx":"14000000"}, {"sbzlx":"320100000"} ], "newSBID": [ {"sbzlx":"14000000"}, {"sbzlx":"320100000"} ] ,"newSBLX":[{"sbzlx":"14000000"},{"sbzlx":"14000000"}],"newSerZyno": [ {"sbzlx":"14000000"}, {"sbzlx":"320100000"} ]}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值
     * {"success":true,"msg":"200:OK","data":{"newSBID":{"320100000":[{"no":"SBID00000027763E06819D4B3CBEED1B241EEC432C","sbzlx":"320100000"}],"14000000":[{"no":"SBID0000003EC39941BCD44703ACF607A0492CD806","sbzlx":"14000000"}]},"newSBLX":{"14000000":[{"no":"{\"sblxbm\":\"140000\",\"sblxmc\":\"超连接线\"}","sbzlx":"14000000"},{"no":"{\"sblxbm\":\"140000\",\"sblxmc\":\"超连接线\"}","sbzlx":"14000000"}]},"newConno":{"320100000":[{"no":"2844","sbzlx":"320100000"}],"14000000":[{"no":"2844","sbzlx":"14000000"}]},"newSerno":{"320100000":[{"no":"100000037","sbzlx":"320100000"}],"14000000":[{"no":"100000144","sbzlx":"14000000"}]},"newSerZyno":{"320100000":[{"no":"100000022","sbzlx":"320100000"}],"14000000":[{"no":"100000142","sbzlx":"14000000"}]}}}
     */
    @PostMapping("/getNewSer")
    ResponseResult getNewSer(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        return deviceService.getNewSer(serviceRequest.getData());
    }
    //本地测试
  /*  ResponseResult getNewSer(@RequestBody JSONObject serviceRequest) {
        return deviceService.getNewSer(serviceRequest);
    }*/



    /**
     * @api {post} /datagovernance/device/getWorkOrderDetail 9、获取本地朗新工单明细(业扩、高压核查)
     * @apiGroup device
     * @apiName getWorkOrderDetail
     * @apiDescription 获取朗新工单下的变压器信息（task_yk）
     * @apiVersion 1.0.0
     * @apiParam {String} gdtype  工单类型：3-业扩 4-高压核查
     * @apiParam {String} taskid  工单类号
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "app_getWorkOrderDetail", "data":{"serviceCode":"app_getWorkOrderDetail","gdtype":"4","taskid":"2021042500000003181453515"}}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"返回成功","result":[{"sbid":"1763226","sbmc":"1#","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"1814930","sbmc":"中北大学","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"5972288","sbmc":"测试中心1#","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"5972290","sbmc":"测试中心2#","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"99996495392","sbmc":"中北大学7#配电室2#变","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"99996495389","sbmc":"中北大学7#配电室1#变","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"5746182","sbmc":"中北大学","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"5746178","sbmc":"中北大学","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"1880063","sbmc":"5#","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"1880550","sbmc":"3#","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"1881431","sbmc":"4#","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"4949913","sbmc":"中北大学所变","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"4949915","sbmc":"中北大学1000","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"4949919","sbmc":"中北大学630","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"4949917","sbmc":"中北大学800","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"1765672","sbmc":"9#","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"99996993196","sbmc":"实训楼1#变","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781},{"sbid":"99996993202","sbmc":"实训楼2#变","schemaId":41,"ssdz":0,"ssxl":1651781,"taskid":"2021042500000003181453515","tqId":1651781}]}
     */
        @PostMapping({"/getWorkOrderDetail"})
    public ResponseResult getWorkOrderDetail(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        JSONObject jsonObject = serviceRequest.getData();
        log.info("getWorkOrderDetail原始参数：{}", jsonObject);
//        Map<String,Object > param =new HashMap<>();
        //工单类型： 3-业扩 4-高压核查
        String gdtype = jsonObject.getString(SysConstant.FIELD_GDTYPE);
        String taskid = jsonObject.getString("taskid");
        if (StrUtil.isEmpty(gdtype)) {
            throw new BizException("工单类型不能为空");
        }
        if (!gdtype.equals(SysConstant.TASK_STATE_YK) && !gdtype.equals(SysConstant.TASK_STATE_HIGH_CHECK)) {
            throw new BizException("工单类型不存在");
        }
        if (StrUtil.isEmpty(taskid)) {
            throw new BizException("工单号不能为空");
        }
        List<TYwTaskYk> workOrderDetail = deviceService.getWorkOrderDetail(gdtype, taskid);
        log.info("getWorkOrderDetail结果：{}", JSON.toJSONString(workOrderDetail));
        return ResponseResult.success(workOrderDetail);
    }

    /**
     * @api {post} /datagovernance/device/getSignInfo 10、查询当前用户是否签到
     * @apiGroup device
     * @apiName getSignInfo
     * @apiDescription 查询当前用户是否签到 , success为true为已登录
     * @apiVersion 1.0.0
     * @apiParam {String} versionid  版本号
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "app_getSignInfo", "data": {"versionid":"123"} }
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"返回成功","result": null}
     */
    @PostMapping("/getSignInfo")
    public ResponseResult getSignInfo(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        String versionid = serviceRequest.getData().getString("versionid");
        if (StrUtil.isNotEmpty(versionid)) {
            DecodeTokenInfoDTO dto = JwtUtils.getAllDecodeTokenInfo(token);
            AppLogDto logDto = new AppLogDto(dto.getLoginName(), dto.getUserName(), SysConstant.OPERATE_SIGNIN);
            logDto.setRelation1(versionid);
            //已存在当前用户已完成签到!
            List<AppLogDto> list = userDao.getAppLogs(logDto);
            if (list != null && list.size() > 0) {
                return ResponseResult.success(null);
            } else {
                return ResponseResult.failed("尚未签到");
            }
        }
        return ResponseResult.failed("versionid不能为空");
    }

    /**
     * @api {post} /datagovernance/device/insertXL 11、新建线路
     * @apiGroup device
     * @apiName insertXL
     * @apiDescription 新建线路
     * @apiVersion 1.0.0
     * @apiParam {String} versionid  版本号
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "app_getSignInfo", "data": [{"oid":"1","fhid":"1","fhjd":"1","fhdx":"1","fhys":"1","sfbz":"1","dhzs":"1","bzxszd":"1","bznr":"1","x":"1","y":"1","sfyc":"1","versionid":"1","addflag":"1","sbzlx":"310000000","sbmc":"1","yxdw":"1","ssds":"1","sszrq":"1","sbid":"1","apptype":"1","yxbh":"1","dydj":"1","sjxl":"1","byqlx":"1","ssbyq":"1","cxkg":"1","qsdsb":"1","qsdsblx":"1","qsdzlx":"1","cxjglx":"1","sstqlx":"1","sstq":"1","sjsbzlx":"1","sjsbid":"1","istail":"1","schema_id":"1"},{"obj_id":"1","xlmc":"1","dxmpyxkid":"1","sbbm":"1","yxbh":"1","byqlx":"1","dydj":"1","yxzt":"1","tyrq":"2021-03-30 16:42:01","xllx":"1","zcdw":"1","zcbh":"1","bz":"1","djsj":"2021-03-30 16:42:01","sbzr":"1","zcdwmc":"1","ssdsmc":"1","sbzrmc":"1","fbzt":"1","zyfl":"1","xghsbmc":"1","sbzlx":"310000000"}] }
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"返回成功","result": null}
     */
    @PostMapping("/insertXL")
    public ResponseResult insertXL(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.insertXL(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/getDevicesFromTQ 12、获取任务内的变压器列表
     * @apiGroup device
     * @apiName getDevicesFromTQ
     * @apiDescription 获取任务内的变压器列表，根据版本号，到下发的数中查询
     * @apiVersion 1.0.0
     * @apiParam {String} gdtype 工单类型：1为专线，台区为2
     * @apiParam {String} versionid 工单号
     * @apiParam {List} sbzlxs  设备子类型("11000000":"柱上-变压器","11000001":"柱上-用户变压器","11000002":"柱上-变压器(专变公用)","23000000":"站外一次-变压器绕组","30100001":"主变压器-自耦","30100002":"主变压器-双绕组","30100003":"主变压器-三绕组","30100004":"主变压器-四绕组","30100005":"主变压器-有抽头自耦","30200000":"配电变压器-三绕组","30200001":"配电变压器-自耦","30200002":"配电变压器-双绕组","30200003":"配电变压器-用户","30200004":"配电变压器-专变公用","39200000":"站内一次-变压器绕组")
     * @apiParam {String} currPage 当前页(不传默认1)
     * @apiParam {String} pageSize 每页条数(不传默认20)
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "app_getDevicesFromTQ", "data": {"gdtype":"2","versionid":"100723054","sbzlxs":["11000000","30200003"],"currPage":"1","pageSize":"2"} }
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"响应成功","data":{"records":[{"sbmc":"10kV924道北线晋华八一宿舍变","classid":110000,"shape":"LINESTRING(112.736892447 37.705123612,112.736884922 37.705126569,112.736877397 37.705129526)","sbzlx":11000000,"datatype":"1","geotype":"2002","modelalias":"柱上-变压器","tqsbid":"24002EFA-7752-40C2-8D59-68F6137A93CB-73078","sboid":688485,"oid":688485,"sbid":"24002EFA-7752-40C2-8D59-68F6137A93CB-73078","points":[{"x":112.73489244700001,"y":37.702123612},{"x":112.734884922,"y":37.702126569},{"x":112.734877397,"y":37.702129526}]}],"total":1,"size":2,"current":1,"orders":[],"searchCount":true,"pages":1}}
     */
    @PostMapping("/getDevicesFromTQ")
    public ResponseResult getDevicesFromTQ(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.getDevicesFromTQ(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/getUpdateDeviceForShape 13、根据当前设备获取周围设备的topo关系
     * @apiGroup device
     * @apiName getUpdateDeviceForShape
     * @apiDescription 根据当前设备获取周围设备的topo关系，用于修改、移动、删除设备
     * @apiVersion 1.0.0
     * @apiParam {String} sbzlx 设备子类型
     * @apiParam {String} oid 主键
     * @apiParam {String} gdtype 工单类型
     * @apiParam {String} versionid 工单号
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "getUpdateDeviceForShape", "data": {"sbzlx":"10200000","oid":"7104622","gdtype":"1","versionid":"1234567"} }
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"响应成功","data":[{"ssdx":3387886,"ssxl":654985,"shape":"LINESTRING(112.441450711797 37.7191646655401,112.441440850058 37.7191369383421,112.441222341789 37.7187162533923,112.441142386553 37.7185213529208,112.441124056897 37.7184864712049,112.441044386997 37.7183213027294)","geotype":"2002","tqsbid":"SBID000000D2EB27BF01874689A4724FED6514A7F4","oid":4255855,"type":"LINESTRING","points":[{"x":112.43945071179701,"y":37.7161646655401},{"x":112.439440850058,"y":37.7161369383421},{"x":112.439222341789,"y":37.7157162533923},{"x":112.439142386553,"y":37.7155213529208},{"x":112.439124056897,"y":37.7154864712049},{"x":112.43904438699701,"y":37.7153213027294}],"sbmc":"10kV944赤桥线080号-10kV944赤桥线075号","classid":101000,"dydj":22,"zzgt":7780081,"sbzlx":10100000,"datatype":"1","modelalias":"导线段","sboid":4255855,"qsgt":7780241,"toponodeid":"92272362,7510963","disoid":4255855,"sbid":"SBID000000F40BEA55BBC343C680EE9D07FB0433EE"},{"ssdx":3387888,"ssxl":654985,"shape":"LINESTRING(112.440064484399 37.7162601014664,112.4400164 37.71627867)","geotype":"2002","tqsbid":"SBID000000D2EB27BF01874689A4724FED6514A7F4","oid":4255878,"type":"LINESTRING","points":[{"x":112.438064484399,"y":37.7132601014664},{"x":112.43801640000001,"y":37.71327867}],"sbmc":"10kV944赤桥线065号-10kV944赤桥线65号西支001号导线","classid":101000,"dydj":22,"zzgt":7780082,"sbzlx":10100000,"datatype":"1","modelalias":"导线段","sboid":4255878,"qsgt":7780081,"toponodeid":"103107115,7510967","disoid":4255878,"sbid":"SBID00000029D2A54A80314B0A9EFB88D3C8CADB79"},{"ssdx":3388323,"ssxl":654985,"shape":"POINT(112.432946958253 37.7066265205084)","geotype":"2001","tqsbid":"SBID000000D2EB27BF01874689A4724FED6514A7F4","oid":8576429,"type":"POINT","points":[{"x":112.430946958253,"y":37.7036265205084}],"sbmc":"10kV944赤桥线059号","classid":102000,"dydj":22,"sbzlx":10200000,"datatype":"1","modelalias":"直线-运行杆塔","sswlg":9401525,"sboid":8576429,"toponodeid":"0","disoid":8576429,"sbid":"16AEEABE-1F8C-4386-87AA-7757B399B640-14671"},{"shape":"POINT(112.439997047343 37.7011411895253)","geotype":"2001","tqsbid":"SBID000000D2EB27BF01874689A4724FED6514A7F4","oid":8581163,"type":"POINT","points":[{"x":112.437997047343,"y":37.6981411895253}],"sbmc":"10kV944赤桥线042号","classid":103000,"dydj":0,"sbzlx":10300001,"datatype":"1","modelalias":"耐张-物理杆塔","sboid":8581163,"toponodeid":"-1","disoid":8581163,"sbid":"16AEEABE-1F8C-4386-87AA-7757B399B640-14630"}]}
     */
    @PostMapping("/getUpdateDeviceForShape")
    public ResponseResult getUpdateDeviceForShape(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.getTopDevices(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/updateDeviceShape 14、修改设备信息（包括坐标）
     * @apiGroup device
     * @apiName updateDeviceShape
     * @apiDescription 修改设备信息（包括坐标）
     * @apiVersion 1.0.0
     * @apiParam {list} updateModels 修改设备的数据
     * @apiParam {String} gdtype 工单类型
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "app_updateDeviceShape", "data": {"updateModels":[{"ssdx":3388323,"ssxl":654985,"shape":"POINT(112.432946958253 37.7066265205084)","geotype":"2001","tqsbid":"SBID000000D2EB27BF01874689A4724FED6514A7F4","oid":9829916,"type":"POINT","points":[{"x":112.430946958253,"y":37.7036265205084}],"sbmc":"饶翠的测试数据数据","classid":102000,"dydj":22,"sbzlx":10200001,"datatype":"1","modelalias":"直线-运行杆塔","sswlg":9401525,"sboid":8576429,"toponodeid":"0","disoid":9829916,"sbid":"4ACEr169-4625-4F04-BE23-5BA50E349812"}],"gdtype":"1"},"governanceToken":"123" }
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"响应成功","data":{"success":true,"msg":"返回成功","data":{"features":[{"geometry":{"coordinates":[112.430946958253,37.7036265205084],"type":"POINT"},"type":"Feature","properties":{"ssxl":654985,"conn":"0","zw_type":102000,"typeName":"直线-运行杆塔","yxdw":null,"oid":9829916,"ssxlName":"10kV赤桥线944","sbmc":"饶翠的测试数据数据","fhjd":null,"dydj":22,"sbzlx":10200001,"sswlg":9401525,"sswlgName":"10kV944赤桥线059号","sbid":"4ACEr169-4625-4F04-BE23-5BA50E349812"}}],"type":"FeatureCollection"}}}
     */
    @PostMapping("/updateDeviceShape")
    public ResponseResult updateDeviceShape(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.updateDeviceShape(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/deleteDevices 15、删除设备信息（包括坐标）
     * @apiGroup device
     * @apiName deleteDevices
     * @apiDescription 删除设备信息（包括坐标）
     * @apiVersion 1.0.0
     * @apiParam {list} updateModels 修改设备的数据
     * @apiParam {String} gdtype 工单类型
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "app_updateDeviceShape", "data": {"updateModels":[{"ssdx":3388323,"ssxl":654985,"shape":"POINT(112.432946958253 37.7066265205084)","geotype":"2001","tqsbid":"SBID000000D2EB27BF01874689A4724FED6514A7F4","oid":9829916,"type":"POINT","points":[{"x":112.430946958253,"y":37.7036265205084}],"sbmc":"饶翠的测试数据数据","classid":102000,"dydj":22,"sbzlx":10200001,"datatype":"1","modelalias":"直线-运行杆塔","sswlg":9401525,"sboid":8576429,"toponodeid":"0","disoid":9829916,"sbid":"4ACEr169-4625-4F04-BE23-5BA50E349812"}],"gdtype":"1"},"governanceToken":"123" }
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"响应成功","data":{"success":true,"msg":"返回成功","data":{"features":[{"geometry":{"coordinates":[112.430946958253,37.7036265205084],"type":"POINT"},"type":"Feature","properties":{"ssxl":654985,"conn":"0","zw_type":102000,"typeName":"直线-运行杆塔","yxdw":null,"oid":9829916,"ssxlName":"10kV赤桥线944","sbmc":"饶翠的测试数据数据","fhjd":null,"dydj":22,"sbzlx":10200001,"sswlg":9401525,"sswlgName":"10kV944赤桥线059号","sbid":"4ACEr169-4625-4F04-BE23-5BA50E349812"}}],"type":"FeatureCollection"}}}
     */
    @PostMapping("/deleteDevices")
    public ResponseResult deleteDevices(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.deleteDevices(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/dynamicDeviceForm 15、获取设备编辑的动态表单信息
     * @apiGroup device
     * @apiName dynamicDeviceForm
     * @apiDescription 获取设备编辑的动态表单
     * @apiVersion 1.0.0
     * @apiParam {list} updateModels 修改设备的数据
     * @apiParam {String} gdtype 工单类型
     * @apiParamExample {json} 传参示例-RequestParam
     * {"serviceCode":"app_dynamicDeviceForm","governanceToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI3QTVCRDdGRTY5QkE0RkU4QTREMENEMTIwMkRBMDVGQSIsIm9yZ05vIjoiMTQ0MDExMiIsImlzcyI6IkhVQVlZSS1TWC1EQVRBLU1BTkFHRVIiLCJleHAiOjE2MjA3OTQ4MjIsInVzZXJOYW1lIjoi546L5b-X5YuHIiwidXNlck9yZ0luZm9MZXZlbEluZm8iOnsic2J6ciI6Indhbmd6eTYwMDAxIiwib3Jnbm8iOiIxNDQwMTEyIiwic3Nkc21jIjoi5Zu9572R5aSq5Y6f5L6b55S15YWs5Y-4Iiwic2J6cm1jIjoi546L5b-X5YuHIiwic3NkcyI6IjA1NzI1MkRGNDkwRDQ1RTZFMDUwMDA3RjAxMDA3NDM3IiwieXhkdyI6ImZmODA4MDgxNTA4NDY1MDIwMTUwYTZkZjI1N2UxYmQxIiwieXhkd21jIjoi5Zu9572R5aSq5Y6f5biC5a6i5oi35pyN5Yqh5Lit5b-DIn0sImlhdCI6MTYyMDE5MDAyMiwidXNlcklkIjoiN0E1QkQ3RkU2OUJBNEZFOEE0RDBDRDEyMDJEQTA1RkEifQ.Gy8B_-ClidfHDliH-LURngt6SLQkTefkjGXng-M7Egk","data":{"sbzlx":"11000000","sbid":"1730008","oid":"689765","versionid":"101991437","gdtype":"4"}}
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"响应成功","data":[{"fieldAlias":"运行单位","isRequired":false,"fieldName":"yxdw","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":"ff808081508465020150a6df257e1bd1"},{"fieldAlias":"电压等级","isRequired":false,"fieldName":"dydj","isEditable":false,"isSearch":true,"optional":[{"code":21,"codename":"交流6kV"},{"code":22,"codename":"交流10kV"},{"code":23,"codename":"交流15.75kV"},{"code":24,"codename":"交流20kV"},{"code":25,"codename":"交流35kV"},{"code":30,"codename":"交流66kV"},{"code":31,"codename":"交流72.5kV"},{"code":32,"codename":"交流110kV"},{"code":33,"codename":"交流220kV"},{"code":34,"codename":"交流330kV"},{"code":35,"codename":"交流500kV"},{"code":36,"codename":"交流750kV"},{"code":37,"codename":"交流1000kV"},{"code":76,"codename":"直流35kV"},{"code":77,"codename":"直流30kV"},{"code":78,"codename":"直流50kV"},{"code":80,"codename":"直流120kV"},{"code":81,"codename":"直流125kV"},{"code":82,"codename":"直流400kV"},{"code":83,"codename":"直流500kV"},{"code":84,"codename":"直流660kV"},{"code":85,"codename":"直流800kV"},{"code":86,"codename":"直流1000kV"},{"code":87,"codename":"直流200kV"},{"code":88,"codename":"直流320kV"},{"code":90,"codename":"直流166.7kV"},{"code":91,"codename":"直流1100kV"},{"code":92,"codename":"直流600kV"},{"code":93,"codename":"直流550kV"},{"code":94,"codename":"直流150kV"}],"isVisible":false,"fieldValue":0},{"fieldAlias":"杆塔材质","isRequired":true,"fieldName":"gtcz","isEditable":true,"isSearch":true,"optional":[{"code":1,"codename":"角钢塔"},{"code":2,"codename":"钢管塔"},{"code":3,"codename":"钢管杆"},{"code":4,"codename":"水泥杆"},{"code":5,"codename":"铁杆"},{"code":6,"codename":"木杆"},{"code":9,"codename":"其他"}],"isVisible":true,"fieldValue":4},{"fieldAlias":"设备子类型","isRequired":false,"fieldName":"sbzlx","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":10300001},{"fieldAlias":"所属责任区","isRequired":false,"fieldName":"sszrq","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":4274},{"fieldAlias":"所属地市","isRequired":false,"fieldName":"ssds","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":"057252DF490D45E6E050007F01007437"},{"fieldAlias":"系统类型","isRequired":true,"fieldName":"apptype","isEditable":true,"isSearch":true,"optional":[{"code":3,"codename":"运检设备"},{"code":5,"codename":"营销设备"}],"isVisible":true,"fieldValue":5},{"fieldAlias":"是否门架","isRequired":false,"fieldName":"sfmj","isEditable":false,"isSearch":true,"optional":[{"code":0,"codename":"否"},{"code":1,"codename":"是"}],"isVisible":false,"fieldValue":0},{"fieldAlias":"杆塔形状","isRequired":false,"fieldName":"gtxz","isEditable":false,"isSearch":true,"optional":[{"code":1,"codename":"方形"},{"code":2,"codename":"其他"}],"isVisible":false,"fieldValue":""},{"fieldAlias":"状态ID","isRequired":false,"fieldName":"state_id","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":48671297},{"fieldAlias":"运行编号","isRequired":false,"fieldName":"yxbh","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":""},{"fieldAlias":"设备ID","isRequired":false,"fieldName":"sbid","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":"wlg41311608931419000107"},{"fieldAlias":"设备名称","isRequired":true,"fieldName":"sbmc","isEditable":true,"isSearch":false,"optional":"","isVisible":true,"fieldValue":"太原市民营经济开发区管理委员会(0100024288)支线001号杆"},{"fieldAlias":"主键OID","isRequired":false,"fieldName":"oid","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":8572597},{"fieldAlias":"所在图形任务ID","isRequired":false,"fieldName":"versionid","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":0},{"fieldAlias":"坐标(json格式)","isRequired":false,"fieldName":"points","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":""},{"fieldAlias":"坐标(数据库格式)","isRequired":false,"fieldName":"shape","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":""},{"fieldAlias":"坐标格式","isRequired":false,"fieldName":"geotype","isEditable":false,"isSearch":false,"optional":"","isVisible":false,"fieldValue":""}]}
     */
    @PostMapping("/dynamicDeviceForm")
    public ResponseResult dynamicDeviceForm(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        return deviceService.dynamicDeviceForm(serviceRequest.getData());
    }

    /**
     * @api {post} /datagovernance/device/getStatisticsForTask 16、工单任务数量统计（首页待办和已办）
     * @apiGroup device
     * @apiName getStatisticsForTask
     * @apiDescription 工单任务统计，首页待办和已办数量查询展示
     * @apiVersion 1.0.0
     * @apiParam {list} updateModels 修改设备的数据
     * @apiParam {String} gdtype 工单类型
     * @apiParamExample {json} 传参示例-RequestParam
     * { "serviceCode": "app_getStatisticsForTask", "data":{"orgNo":"1440112","serviceCode":"app_getStatisticsForTask","gdtype":"4","userid":"7A5BD7FE69BA4FE8A4D0CD1202DA05FA"},"governanceToken":"123" }
     * @apiSuccess {Boolean} success 是否调用成功
     * @apiSuccess {String} msg 返回消息
     * @apiSuccess {String} result 返回结果
     * @apiSuccessExample {json} 成功返回值 result 从朗新同步的工单数
     * {"success":true,"msg":"响应成功","data":{"doing":5,"done":9}}
     */
    @PostMapping("/getStatisticsForTask")
    public ResponseResult getStatisticsForTask(@RequestBody YzyServiceRequest<JSONObject> serviceRequest) {
        String token = serviceRequest.getGovernanceToken();
        if (StrUtil.isBlank(token)) {
            return ResponseResult.failed("governanceToken为空");
        }
        DecodeTokenInfoDTO dto = JwtUtils.getAllDecodeTokenInfo(token);
        JSONObject jsonObject = serviceRequest.getData();
        jsonObject.put("userid", dto.getUserId());
        HashMap<String, String> orgMap = dto.getUserOrgInfoLevelInfoMap();
        jsonObject.put("orgNo", orgMap.get("orgNo"));
        return deviceService.getStatisticsForTask(serviceRequest.getData());
    }

}
